package com.gxar.quick.ar.server.base.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gxar.common.entity.login.UserProfile;
import com.gxar.common.utils.StringUtils;
import org.apache.logging.log4j.util.Strings;

/**
 * @author nice
 * @version 1.0
 * @created 2023/11/16.
 */
public class TransferUtils {

    public static String getOpenId(String appid, UserProfile userProfile) {
        String extra = userProfile.getExtra();
        if (StringUtils.isBlank(extra) || StringUtils.isBlank(appid)) {
            return Strings.EMPTY;
        }
        JSONObject extraObject = JSON.parseObject(extra);
        Object appInfo = extraObject.get(appid);
        if (appInfo == null) {
            return Strings.EMPTY;
        }
        JSONObject appJson = JSON.parseObject(JSON.toJSONString(appInfo));
        return appJson.getString("openid");
    }
}
